<?php $this->renderPartial('//common/header'); ?>
<?php
	// Tao session luu tru captcha

?>
<div id="main">
	<div class="container">
		<div class="banner" style="background:url('<?php
			echo yii::app()->baseUrl."/upload/images/".$this->arrSystem[0]->banner;
		?>') no-repeat scroll center top / cover  rgba(0, 0, 0, 0)">
			<a href="#" class="view"><i class="icon icon-arrow-right-lg"></i></a>
		</div>
		<div class="box-register">
			<form action="" id="submitRegister" class="form form-register">
				<input type="text" name="name" class="form-control" placeholder="Tên tổ chức - cá nhân">
				<input type="text" name="phone" class="form-control" placeholder="Điện thoại">
				<input type="text" name="email" class="form-control" placeholder="Địa chỉ email">
				<select name="id_price" class="form-control" style="font-size:11px !important;">
					<?php if(!empty($arrPrice)){ ?>
						<?php foreach($arrPrice as $k=>$v){ ?>
							<option value="<?php echo $k; ?>"><?php echo $v; ?></option>
						<?php } ?>
					<?php } ?>
				</select>
				<div class="wrap-input-captcha">
					<img class="captcha" src="<?php echo PIUrl::createUrl('/home/stringToImage');?>"/>
					<input type="text" name="captcha" class="form-control">
				</div>
				<button type="submit" class="btn-dark btn-submit">Gửi đăng ký</button>
			</form>
		</div>
		<div class="clearfix"></div>
		<div class="box-hightlight">
			<div class="col-left">
				<div class="inner">
					<h2 class="title">Website đăng ký nhiều trong tuần</h2>
				</div>
			</div>
			<div class="col-right">
				<span class="icon bg-slide-left"></span>
				<span class="icon bg-slide-right"></span>
				<div id="owl-carousel" class="owl-carousel">
					<div class="item-inner">
						<a href="#"><img src="<?php echo Yii::app()->theme->baseUrl;?>/img/photo/img-01.jpg" alt="img" width="155" height="125"></a>
					</div>
					<div class="item-inner">
						<a href="#"><img src="<?php echo Yii::app()->theme->baseUrl;?>/img/photo/img-02.jpg" alt="img" width="155" height="125"></a>
					</div>
					<div class="item-inner">
						<a href="#"><img src="<?php echo Yii::app()->theme->baseUrl;?>/img/photo/img-03.jpg" alt="img" width="155" height="125"></a>
					</div>
					<div class="item-inner">
						<a href="#"><img src="<?php echo Yii::app()->theme->baseUrl;?>/img/photo/img-04.jpg" alt="img" width="155" height="125"></a>
					</div>
					<div class="item-inner">
						<a href="#"><img src="<?php echo Yii::app()->theme->baseUrl;?>/img/photo/img-01.jpg" alt="img" width="155" height="125"></a>
					</div>
					<div class="item-inner">
						<a href="#"><img src="<?php echo Yii::app()->theme->baseUrl;?>/img/photo/img-02.jpg" alt="img" width="155" height="125"></a>
					</div>
				</div>
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="wrap-heading-new-design">
			<h2 class="title"><?php echo translate("Giao diện mới nhất"); ?></h2>
			<form action="home/theme" class="form form-search">
				<div class="group-form-control">
					<input type="hidden" name="id"  value="<?php echo (isset($_GET['id']) ? $_GET['id'] : null); ?>">
					<input type="search" name="name" class="form-control" placeholder="Tìm theo danh sách">
					<button type="submit" name="search" class="text-hide icon-ib icon-search">Tìm</button>
				</div>
			</form>
			<div class="clearfix"></div>
		</div>
		<div class="box-list-item">
		<?php if(!empty($arrCateTheme)){ ?>
			<ul>
				<?php foreach($arrCateTheme as $cateTheme){ ?>
					<li><a class="<?php echo ((isset($_GET['id']))&& $_GET['id'] == $cateTheme->id) ? 'active' : ''; ?>" href="<?php echo PIUrl::createUrl('/home/theme', array('alias'=>$cateTheme->alias));?>"><?php echo $cateTheme->name; ?></a></li>
				<?php } ?>
				<li><a class="<?php echo (!isset($_GET['id'])) ? 'active' : ''; ?>" href="<?php echo PIUrl::createUrl('/home/theme');?>">Tất cả</a></li>
			</ul>
		<?php } ?>
		</div>
		<div class="box-list-preview">
		<?php if(!empty($arrTheme)){ ?>
			<ul id="themes">
				<?php foreach($arrTheme as $theme){ ?>
					<li class="themes">
						<a href="<?php echo PIUrl::createUrl('/home/themeDetail/', array('alias'=>$theme->alias));?>">
							<div class="wrap-image">
								<img src="<?php echo getImage($theme->image, 223, 165) ?>" alt="img" width="223" height="165">
								<i class="icon-ib icon-view"></i>
							</div>
							<h4><?php echo $theme->name; ?></h4>
						</a>
					</li>
				<?php } ?>
			</ul>
		<?php } ?>
		</div>
	</div>
	<div class="loading" style="height:5px;">
	</div>

	<div class="box-list-news">
		<div class="container">
			<?php if(!empty($arrCategories)){ $i=0; ?>
			<?php foreach($arrCategories as $category){ $i++; ?>
			<div class="<?php echo ($i==1) ? "col-left" : "col-right"; ?>">
				<a href="<?php echo PIUrl::createUrl('/home/listNews/', array("alias"=>$category->alias));?>"><h2 class="title"><?php echo $category->name; ?></h2></a>
				<?php if(!empty($arrNew)){ ?>
				<ul class="list-news">
					<?php $k=0; foreach($arrNew as $new){ ?>
					<?php if($new->category_news_id == $category->id){ $k++ ?>
					<li>
						<a href="<?php echo PIUrl::createUrl('/home/newDetail/', array("alias"=>$new->alias));?>" class="wrap-img"><img src="<?php echo getImage($new->image, 121, 90); ?>" alt="img"></a>
						<div class="content-detail">
							<h3 class="news-title"><a href="<?php echo PIUrl::createUrl('/home/newDetail/', array("alias"=>$new->alias));?>"><?php echo $new->name; ?></a></h3>
							<p class="news-date"><i class="icon-fl icon-calendar"></i><?php echo "Đăng ngày ".date("d/m/Y",$new->created); ?></p>
							<p class="news-content-brief"><?php echo word_limiter($new->description,22); ?></p>
						</div>
					</li>
					<?php if($k == 2) break; ?>
					<?php } ?>
					<?php } ?>
				</ul>
				<?php } ?>
			</div>
			<?php } ?>
			<?php } ?>
		</div>
	</div>
</div>
<div id="push"> </div>
</div>
<script>
	// function validate email
	function ValidateEmail(mail)   
	{  
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))  
	  {  
		return true;  
	  }  else return false;
	}  
	
	$(document).ready(function(){
		$("#submitRegister").submit(function(){
			var data = $('form').serialize();
			var error = true; var errorEmail = true;
			var i=0;
			$("#submitRegister .form-control").each(function(){
				i++;
				//validate email
				if(i == 3){
					if(ValidateEmail($(this).val()) == false){
						$(this).attr("class", "form-control error");
						errorEmail = false;
					}else{
						$(this).attr("class", "form-control");
					}
				}else{
					// validate cac truong con lai
					if($(this).val() == ""){
						$(this).attr("class", "form-control error");
						error = false;
					}else{
						$(this).attr("class", "form-control");
					}
				}
			});
			
			if(error == true){
				if(errorEmail ==  true){
					$.ajax({url: webroot +"/home/registerTheme/",data:data,type:'post',success:function(data){
						if(data == "true"){
							alert("Gủi đăng ký thành công!");
							$("img.captcha").prop("src", "<?php echo PIUrl::createUrl('/home/stringToImage');?>");
							$("#submitRegister .form-control").each(function(){
								$(this).val("");
							});
						}
						else{
							$("img.captcha").prop("src", "<?php echo PIUrl::createUrl('/home/stringToImage');?>?"+new Date().getTime());
							$(".wrap-input-captcha input").attr("class", "form-control error");
							alert("Mã xác nhận không hợp lệ");
						}
					}});
				}else{
					alert("Địa chỉ email không hợp lệ!");
				}
			}else{
				alert("Vui lòng điền đầy đủ thông tin yêu cầu!");
			}
			
			return false
		});
	});
</script>
<style>
.error{border-color: #69B608 !important;}
</style>
<?php $this->renderPartial('//common/footer'); ?>